package guava;

import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.Collection;
import java.util.List;
import java.util.Objects;

/**
 * 断言
 * 最常用的功能就是运用在集合的过滤当中！
 *
 * @author Daniel
 */
public class PredicateTest {

    public static void main(String[] args) {

        List<String> list = Lists.newArrayList("aba", "jack");

        Collection<String> result = Collections2.filter(list, new Predicate<String>() {
            @Override
            public boolean apply(@Nullable String input) {
                // 判断逻辑
                Objects.requireNonNull(input);
                return new StringBuilder(input).reverse().toString().equals(input);
            }
        });

        result.forEach(System.out::println);
    }

}
